/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import DAO.DAOFactory;
import DAO.Financial.CompanyDAO;
import DAO.Financial.MarketDAO;
import DAO.exceptions.PreexistingEntityException;
import FinancialEntity.Company;
import FinancialEntity.Market;
import VO.CompanyVO;
import VO.MarketVO;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Sebastian
 */
public class CompanyService {
    
    public void createCompany(CompanyVO companyVo, EntityManager em ) throws PreexistingEntityException, Exception{
        CompanyDAO companydao = (CompanyDAO) DAOFactory.getDAOFinancial(DAOFactory.COMPANY);
        companydao.create(companyVo.toEntity(), em);
    }
    
    public List<CompanyVO> getAllCompanies(EntityManager em){
        CompanyDAO companydao = (CompanyDAO) DAOFactory.getDAOFinancial(DAOFactory.COMPANY);
        List<Company> listaCompanies = companydao.findCompanyEntities(em);
        List<CompanyVO> listaVos = new ArrayList<>();
        for (Company m:listaCompanies){
            listaVos.add(m.toVO());
        }
        return listaVos;
    }
    
}
